package com.psfd.demo.controller;


import com.psfd.demo.entity.BookInformation;
import com.psfd.demo.service.IBookInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 *  前端控制器
 * </p>
 *图书信息
 * @author 撒旦
 * @since 2020-07-10
 */
@RestController
public class BookInformationController {

    @Autowired
    private IBookInformationService bookInformationService;

    //增加
    @RequestMapping("/bookInformationinsert")
    public ModelAndView insert(BookInformation bookInformation){
        ModelAndView modelAndView = new ModelAndView();
        bookInformationService.save(bookInformation);
        modelAndView.addObject("bookinformationList",bookInformationService.list());
        modelAndView.setViewName("BookInformationQuery");
        return modelAndView;
    }

    //修改
    @RequestMapping("/bookInformationupdate")
    public ModelAndView update(BookInformation bookinformation){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("bookinformation",bookinformation);
        modelAndView.setViewName("BookInformationUpdate");
        return modelAndView;
    }

    //修改
    @RequestMapping("/bookInformationupdate1")
    public ModelAndView update1(BookInformation bookInformation){
        bookInformationService.updateById(bookInformation);
        return query();
    }

    //删除
    @RequestMapping("/bookInformationdelete")
    public ModelAndView delete(Integer id){
        ModelAndView modelAndView = new ModelAndView();
        bookInformationService.removeById(id);
        System.err.println("删除的ID为："+id);
        modelAndView.addObject("bookinformationList",bookInformationService.list());
        modelAndView.setViewName("BookInformationQuery");
        return modelAndView;
    }

    //查询
    @RequestMapping("/bookInformationquery")
    public ModelAndView query(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("bookinformationList",bookInformationService.list());
        System.err.println(bookInformationService.list());
        modelAndView.setViewName("BookInformationQuery");
        return modelAndView;
    }

}

